import { _decorator, Node, tween, Label, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
import { UiUtil } from '../../Framework/Utils/UiUtil';
import { BaseTs } from './BaseTs';
import { EventUtil } from '../../Framework/Utils/EventUtil';
import { EventConstant } from '../../Framework/Constants/EventConstant';

@ccclass('ToastTs')
export class ToastTs extends BaseTs {


    @property(Node)
    overlay: Node = null;
    @property
    msg: Node = null;

    start() {



        // this.twn.delay(1).
        //     to(1, { opacity: 0 }, { easing: "sineOut" }).
        //     call(() => {
        //         // TimerMgr.Instance.ScheduleOnce(this.OnRemoveUI, this, 0);
        //         UiUtil.INSTANCE.removePrefabAsset('Toast')
        //     }).start();
    }

    /**
     * 显示Toast
     * @param msg 内容
     */
    public init(msgBo: { msg: string, millisecond: number }) {


        // 显示数据
        this.node.getChildByPath('Layout/Msg/Label').getComponent(Label).string = msgBo.msg;

        if(msgBo.msg === '登录成功') {
            // 回调事件数据
            EventUtil.INSTANCE.invoke(EventConstant.WX_LOGIN_CALLBACK_EVENT , '异步执行成功');
        }

        tween(this.node)
            .delay(0)
            .to(0.1, { position: new Vec3(0, -20, 0) })
            .delay(1)
            .to((msgBo.millisecond || 600) / 1000, { position: new Vec3(0, 400, 0) })
            .call(() => {
                UiUtil.INSTANCE.removePrefabAsset('Toast')
            }).start();
    }



}